# -*- coding: utf-8 -*-
"""
Created on Sun Sep 21 05:27:55 2025

@author: surpass

Student模型类定义
"""

class Student:
    """学生类，表示单个学生的信息和成绩"""
    def __init__(self, student_id, name, class_name, experiments, homeworks,
                 online_learning_70, online_learning_20, online_learning_10,
                 usual_total, final_exam, total_score):
        """初始化学生信息"""
        self.student_id = student_id
        self.name = name
        self.class_name = class_name
        self.experiments = experiments
        self.homeworks = homeworks
        self.online_learning_70 = online_learning_70
        self.online_learning_20 = online_learning_20
        self.online_learning_10 = online_learning_10
        self.usual_total = usual_total
        self.final_exam = final_exam
        self.total_score = total_score
    
    @classmethod
    def from_input(cls):
        """从用户输入创建学生对象"""
        # 基本信息
        student_id = input("请输入学号: ").strip()
        name = input("请输入姓名: ").strip()
        class_name = input("请输入班级: ").strip()
        
        # 实验成绩 (8次)
        experiments = []
        print("请输入8次实验成绩:")
        for i in range(1, 9):
            score = float(input(f"实验{i}: "))
            experiments.append(score)
        
        # 作业成绩 (8次)
        homeworks = []
        print("请输入8次作业成绩:")
        for i in range(1, 9):
            score = float(input(f"作业{i}: "))
            homeworks.append(score)
        
        # 在线学习部分
        online_learning_70 = float(input("请输入在线学习(70%部分)成绩: "))
        online_learning_20 = float(input("请输入在线学习(20%部分)成绩: "))
        online_learning_10 = float(input("请输入在线学习(10%部分)成绩: "))
        
        # 平时总合和期末成绩
        usual_total = float(input("请输入平时总合成绩: "))
        final_exam = float(input("请输入期末成绩: "))
        total_score = float(input("请输入总评成绩: "))
        
        return cls(student_id, name, class_name, experiments, homeworks,
                  online_learning_70, online_learning_20, online_learning_10,
                  usual_total, final_exam, total_score)
    
    def to_dict(self):
        """将学生对象转换为字典"""
        return {
            'student_id': self.student_id,
            'name': self.name,
            'class': self.class_name,
            'experiments': self.experiments,
            'homeworks': self.homeworks,
            'online_learning_70': self.online_learning_70,
            'online_learning_20': self.online_learning_20,
            'online_learning_10': self.online_learning_10,
            'usual_total': self.usual_total,
            'final_exam': self.final_exam,
            'total_score': self.total_score
        }
    
    @classmethod
    def from_dict(cls, data):
        """从字典创建学生对象"""
        return cls(
            data['student_id'],
            data['name'],
            data['class'],
            data['experiments'],
            data['homeworks'],
            data['online_learning_70'],
            data['online_learning_20'],
            data['online_learning_10'],
            data['usual_total'],
            data['final_exam'],
            data['total_score']
        )
    
    def display_info(self):
        """显示学生信息"""
        row = f"{self.student_id:<12} {self.name:<8} {self.class_name:<6} "
        
        # 实验成绩
        for exp in self.experiments:
            row += f"{exp:<6.0f}"
        
        # 作业成绩
        for hw in self.homeworks:
            row += f"{hw:<6.0f}"
        
        # 在线学习和总成绩
        row += f"{self.online_learning_70:<8.0f} {self.online_learning_20:<8.0f} "
        row += f"{self.online_learning_10:<8.0f} {self.usual_total:<8.0f} "
        row += f"{self.final_exam:<6.0f} {self.total_score:<6.0f}"
        
        return row